clear 
global output "output directory here"
 
cd $output
use 1982simple 
forvalue i = 1983/1999 {
	append using `i'simple
	} 
	
drop if eyear == "0-"	
gen yrlen = strlen(year)
gen eyrlen = strlen(eyear)
replace eyear ="" if eyrlen == 1 
gen yr = year
gen eyr = eyear 
replace yr = "19" + year if yrlen == 2
replace eyr = "19" + eyear if eyrlen == 2	 

keep id yr eyr state city org ne* nworker* ind revenue wagesum* equity asset* location cost*  

save temp1, replace 
clear 
use 2000simple 

forvalue i = 2001/2005 {
	append using `i'simple
	} 
drop if eyear == "0-"	
gen yrlen = strlen(year)
gen eyrlen = strlen(eyear)
replace eyear ="" if eyrlen == 1
gen yr = year
gen eyr = eyear 
replace yr = "20" + year if yrlen == 2
replace eyr = "20" + eyear if eyrlen == 2	

keep id yr eyr org ne* nworker* ind revenue wagesum* equity asset* location cost*   

save temp2, replace   

clear 
cd $output
use temp1

append using temp2
destring yr, replace 


gen ksic4 = ind if yr == 1982 | yr == 1983
merge m:1 ksic4 using ksic4to8
drop if _merge == 2
drop _merge

gen ksic5 = ind if yr >= 1984 & yr <= 1989
merge m:1 ksic5 using ksic5to8
drop if _merge == 2
drop _merge

gen ksic6 = ind if yr >= 1990 & yr <= 1997
merge m:1 ksic6 using ksic6to8
drop if _merge == 2
drop _merge
 
gen ksic8 = ksic48 if yr == 1982 | yr == 1983 
replace ksic8 = ksic58 if yr >= 1984 & yr <= 1989
replace ksic8 = ksic68 if yr >= 1990 & yr <= 1997
replace ksic8 = ind if yr >= 1998

destring ksic8, replace 
drop if ksic8 ==.    
 
gen geocode1985 = state + city if yr <= 1985
merge m:1 geocode1985 using geo1985_crosswalk
drop if _merge == 2
drop _merge

gen geocode1990 = state + city if yr >= 1986 & yr <= 1991
merge m:1 geocode1990 using geo1990_crosswalk
drop if _merge == 2
drop _merge

gen geocode = geocode1995_1985 if yr <= 1985
replace geocode = geocode1995_1990 if yr >= 1986 & yr <= 1991
replace geocode = location if yr >= 1992 

gen geo = substr(location,1,5)
destring geo, replace

gen geo2 = substr(location,1,2)
replace geo2 = state if geo2 ==""
destring geo2, replace 
 
 
merge m:1 geo yr using bank_data
drop if _merge == 2
drop _merge

merge m:1 geo yr using bankworker_data
drop if _merge == 2
drop _merge
 
merge m:1 geo yr using service_all 
drop if _merge == 2
drop _merge  
 
bys id yr: gen xx = _N
tab xx
drop if xx > 1
drop xx 
  
gen ind3b = substr(ind,1,3) 
destring ind3b, replace 
drop if ind3b < 311 & yr <= 1989
drop if ind3b < 151 & yr >= 1990
gen id2 = id + eyr
drop id 
rename id2 id

destring eyr, replace
replace eyr =. if eyr < 1500 & eyr  > 2020 
gen ones = 1 
    
gen eage = yr - eyr
sum eage,d
replace eage = 0 if eage < 0
replace eage = . if eage > 100
 
tab org
replace org = "3" if org == "4"  
gen SE = 0 
replace SE = 1 if org == "3" & ne > 0
gen inc = 0 
replace inc = 1 if org == "1"  
gen femaleSE = 0 
replace femaleSE = 1 if org == "3" & ne > 0 & ne == nef 
gen maleSE = 0 
replace maleSE = 1 if org == "3" & ne > 0 & ne == nem 
gen familySE = 0 
replace familySE = 1 if org == "3" & ne == 2 & nem == 1 & nef == 1
 
gen newfirmall = 0 
replace newfirmall = 1 if eage == 0 
gen newfirm = 0 
replace newfirm = 1 if eage == 0 & org == "3"
gen newfirmf = 0 
replace newfirmf = 1 if newfirm == 1 & femaleSE == 1 
gen newfirmm = 0 
replace newfirmm = 1 if newfirm == 1 & maleSE == 1 

gen firm = 0 
replace firm = 1 if org == "3"
gen firmf = 0 
replace firmf = 1 if firm == 1 & femaleSE == 1
gen firmm = 0 
replace firmm = 1 if firm == 1 & maleSE == 1 
 
bys id: egen mxYr = max(yr)  
 
merge m:1 yr using cpi
keep if _merge == 3
drop _merge

replace asset = asset*100/cpi
replace revenue = revenue*100/cpi 
replace equity = equity*100/cpi
replace wagesum = wagesum*100/cpi
replace wagesum_white = wagesum_white*100/cpi
replace wagesum_blue = wagesum_blue*100/cpi 
replace cost_material = cost_material*100/cpi 
replace asset_land = asset_land*100/cpi
replace asset_factory = asset_factory*100/cpi
replace asset_machine = asset_machine*100/cpi
  
gen debt = asset - equity
sum debt,d
replace debt = 0 if debt <= 0 
replace debt = . if yr == 1990 
replace debt = . if firm == 1 
gen y = revenue/(asset - asset_land)  
gen lny = ln(y)  
  

forvalue i = 1982/2005 {  
	gen I`i' = 0 
	replace I`i' = 1 if yr == `i'  
	gen newfirmfI`i' = newfirmf*I`i'
    gen firmfI`i' = firmf*I`i'     
	}   
 
destring geocode, replace
replace geo = geocode


drop ind 
gen ind = ksic8
tostring ind, replace
gen ind2 = substr(ind,1,2) 
destring ind2, replace
gen ind3 = substr(ind,1,3) 
destring ind3, replace


bys ind: gen tag_ind = _n
bys ind yr: gen tag_ind_yr = _n
bys yr: gen tag_yr = _n
bys geo: gen tag_geo = _n 
bys geo yr: gen tag_geo_yr = _n
bys ind2 geo yr: gen tag_ind2_geo_yr = _n 

  
gen after = 0
replace after = 1 if yr >= 1998
gen newfirmfAfter = newfirmf*after
gen firmfAfter = firmf*after
gen before = 1-after
gen firmfBefore = firmf*before
gen newfirmfBefore = newfirmf*before 
 
gen xx = bank_sum if yr == 1997
bys geo: egen B1997 = max(xx)
drop xx

gen xx = bank_sum if yr == 1998
bys geo: egen B1998 = max(xx)
drop xx

gen xx = bankworker_sum if yr == 1997
bys geo: egen BW1997 = max(xx)
drop xx

gen xx = bankworker_sum if yr == 1998
bys geo: egen BW1998 = max(xx)
drop xx
    
gen dbanks = ln(B1997/B1998) 
gen dbanks2 = ln(BW1997/BW1998)  

forvalue i = 1992/2005 {	 
	gen bb`i' = I`i'*dbanks 
	gen dd`i' = I`i'*dbanks2 
	} 

replace bb1997 = 0
replace dd1997 = 0 
replace I1996 = 0

gen after_dbanks = (yr>=1998)*dbanks  
gen after_dbanks2 = (yr>=1998)*dbanks2  

 
sort yr 
bys yr: gen firmallYr = _N
bys yr: egen firmYr = total(firm)
bys yr: egen firmfYr = total(firmf)
bys yr: egen newfirmYr = total(newfirm)
bys yr: egen newfirmfYr = total(newfirmf)
bys yr: egen newfirmmYr = total(newfirmm)
bys yr: egen newfirmallYr = total(newfirmall) 
 
gen ratioF = newfirmfYr/newfirmYr  

bys geo yr: egen Fnewg3 = total(newfirmf)
bys geo yr: egen Mnewg3 = total(newfirmm)  
bys geo yr: egen newg3 = total(newfirm)  

bys ind2 geo yr: egen Fnewg2 = total(newfirmf)
bys ind2 geo yr: egen Mnewg2 = total(newfirmm) 

   
**********FIGURE 1(a)**********
line ratioF yr if tag_yr == 1 & yr >= 1982  

**********FIGURE 1(b)**********
line newfirmfYr yr if tag_yr == 1  
 
**********FIGURE 1(c)**********
reghdfe newfirmf I*  if newfirm == 1 & yr >= 1982, a(ind3) cluster(ind3#yr)
coefplot, vertical keep(I*) yline(0) level(95) recast(scatter) omitted baselevels 

**********FIGURE 1(d)**********
reghdfe firmf I*  if firm == 1 & yr >= 1982, a(ind3) cluster(ind3#yr)
coefplot, vertical keep(I*) yline(0) level(95) omitted baselevels
  
**********TABLE 1: industry composition**********

forvalue i = 15/37 {
	count if newfirmf == 1 & ind2 == `i' & yr >= 1992 & yr <= 1996
}

forvalue i = 15/37 {
	count if newfirmf == 1 & ind2 == `i' & yr >= 1997 & yr <= 2001
}
 
**********TABLE 4: Panal A**********

sum Fnewg3 if tag_geo_yr == 1 & yr >= 1992 & yr <= 1997  
sum Fnewg3 if tag_geo_yr == 1 & yr >= 1998 & yr <= 2005  
sum Mnewg3 if tag_geo_yr == 1 & yr >= 1992 & yr <= 1997  
sum Mnewg3 if tag_geo_yr == 1 & yr >= 1998 & yr <= 2005  


**********TABLE 4 Panal B(county-industry level)**********
sum Fnewg2 if tag_ind2_geo_yr == 1 & yr >= 1992 & yr <= 1997 
sum Fnewg2 if tag_ind2_geo_yr == 1 & yr >= 1998 & yr <= 2005 
sum Mnewg2 if tag_ind2_geo_yr == 1 & yr >= 1992 & yr <= 1997 
sum Mnewg2 if tag_ind2_geo_yr == 1 & yr >= 1998 & yr <= 2005 


**********TABLE 4: Panal C**********
sum dbanks if tag_geo == 1  
gen pos_dbanks = 0   
replace pos_dbanks = 1 if dbanks >0  
sum pos_dbanks if tag_geo == 1 & dbanks !=.  

 
**********TABLE 5 (column (1))**********
reghdfe Fnewg3 after_dbanks if tag_geo_yr == 1 & yr >= 1992 & yr <= 2005, a(yr geo) cluster(geo)
outreg2 using table1, replace tex
reghdfe Mnewg3 after_dbanks if tag_geo_yr == 1 & yr >= 1992 & yr <= 2005, a(yr geo) cluster(geo)
outreg2 using table1, append tex


**********TABLE 5 (column (2))**********
reghdfe Fnewg2 after_dbanks if tag_ind2_geo_yr == 1 & yr >= 1992 & yr <= 2005, a(yr ind2#geo) cluster (geo)
outreg2 using table1, replace tex
reghdfe Mnewg2 after_dbanks if tag_ind2_geo_yr == 1 & yr >= 1992 & yr <= 2005, a(yr ind2#geo) cluster (geo)
outreg2 using table1, append tex

**********Table 5 (column (3))**********

gen severe_shock = 0 
replace severe_shock = 1 if   geo2 == 31 | geo2 == 32 |geo2 == 33 | geo2 == 34 | geo2 == 23  
gen gangwon = 0 
replace gangwon = 1 if geo2 == 32 | geo2 == 33
gen after_treated = after*(1-gangwon)

reghdfe Fnewg3 after_treated if tag_geo_yr == 1 & yr >= 1992 & yr <= 2005 & severe_shock == 1, a(geo yr) cluster(geo)   
outreg2 using table1, replace tex

reghdfe Mnewg3 after_treated if tag_geo_yr == 1 & yr >= 1992 & yr <= 2005 & severe_shock == 1, a(geo yr) cluster(geo)  
outreg2 using table1, append tex 

  
**********FIGURE 3(a)**********
reghdfe Fnewg3 bb* if tag_geo_yr == 1 & yr >= 1992 & yr <= 2005, a(yr geo) cluster(geo) 
coefplot, vertical drop(_cons) yline(0) level(95) omitted baselevels

**********FIGURE 3(b)**********
reghdfe Mnewg3 bb* if tag_geo_yr == 1 & yr >= 1992 & yr <= 2005, a(yr geo) cluster(geo) 
coefplot, vertical keep(bb*) yline(0) level(95) omitted baselevels
  
**********FIGURE 3(c)**********
reghdfe Fnewg2 bb* if tag_ind2_geo_yr == 1 & yr >= 1992 & yr <= 2005, a(yr ind2#geo) cluster(geo)
coefplot, vertical drop(_cons) yline(0) level(95) omitted baselevels

**********FIGURE 3(d)**********
reghdfe Mnewg2 bb* if tag_ind2_geo_yr == 1 & yr >= 1992 & yr <= 2005, a(yr ind2#geo)  cluster(geo)
coefplot, vertical keep(bb*) yline(0) level(95) omitted baselevels

**********Figure 3(e)**********
 
forvalue i = 1992/2005 {  
	gen I2`i' = 0 
	replace I2`i' = 1 if yr == `i'   
	}  
replace I21997 = 0 
forvalue i = 1992/2005 { 
	gen tt`i' = I2`i'*(1-gangwon)  
	}  
reghdfe Fnewg3 tt* if tag_geo_yr == 1 & yr >= 1992 & yr <= 2005 & severe_shock == 1, a(yr geo)  cluster(geo)
coefplot, vertical keep(tt*) yline(0) level(95) omitted baselevels

**********Figure 3(f)**********
reghdfe Mnewg3 tt* if tag_geo_yr == 1 & yr >= 1992 & yr <= 2005 & severe_shock == 1, a(yr geo)  cluster(geo)
coefplot, vertical keep(tt*) yline(0) level(95) omitted baselevels

 
**********TABLE 6 Panel A**********
sort id yr
by id: gen tag_id = _n  

gen Fail = 0 
replace Fail = 1 if mxYr - eyr <= 2
   
bys geo yr: egen xx = mean(Fail) if eage == 0  
bys geo yr: egen y_geo = max(xx)
drop xx 

bys geo yr: egen xx = total(ones)  if eage == 0 
bys geo yr: egen newfirm_geo = max(xx)
drop xx  
 
reghdfe y_geo dbanks if tag_geo_yr == 1 & yr >= 1992 & yr <= 1997 & newfirm_geo > 0, a(yr) 
outreg2 using table1, replace tex
reghdfe y_geo dbanks if tag_geo_yr == 1 & yr >= 1998 & yr <= 2002 & newfirm_geo > 0, a(yr) 
outreg2 using table1, append tex
 

**********TABLE 6 Panel B**********
gen dtoe =debt/equity if inc == 1 & yr !=1990 & asset > equity
replace dtoe = . if dtoe<0
 
bys geo yr: egen xx = mean(dtoe) if inc == 1  & asset > 0 & asset > equity & asset !=. & equity !=.
bys geo yr: egen leverage_geo = max(xx)
drop xx 
  
sum leverage_geo if tag_geo_yr == 1 & yr >= 1992 & yr <= 2005,d 

reghdfe leverage_geo dbanks if tag_geo_yr == 1 & yr >= 1992 & yr <= 1997 & leverage_geo < 23.88042, a(yr)  
outreg2 using table1, replace tex
reghdfe leverage_geo dbanks if tag_geo_yr == 1 & yr >= 1998 & yr <= 2005 & leverage_geo < 23.88042, a(yr)   
outreg2 using table1, append tex
 
 
**********TABLE 6 Panel C**********
bys ind3 yr: egen xx = pctile(lny), p(50)   
bys ind3 yr: egen cutoff3 = max(xx)   
drop xx* 

bys geo yr: egen xx = mean(dtoe) if inc == 1  & asset > 0 & asset > equity & lny < cutoff3 & lny!=.  & cutoff3 !=. & asset !=. & equity !=.
bys geo yr: egen leverage_geo4 = max(xx)
drop xx* 
sum leverage_geo4 if tag_geo_yr == 1 & yr >= 1992 & yr <= 2005,d 

reghdfe leverage_geo4 dbanks if tag_geo_yr == 1 & yr >= 1992 & yr <= 1997 & leverage_geo4 < 30.15123, a(yr)  
outreg2 using table1, replace tex
reghdfe leverage_geo4 dbanks if tag_geo_yr == 1 & yr >= 1998 & yr <= 2005 & leverage_geo4 < 30.15123, a(yr)  
outreg2 using table1, append tex 
    
 
**********FIGURE 4(a)**********
 
forvalue i = 1982/2005 {  
	gen eI`i' = 0 
	replace eI`i' = 1 if eyr == `i'   
    gen firmfeI`i' = firmf*eI`i'     
	}  
		   

reghdfe Fail firmfeI* if tag_id ==1 & eyr >= 1982 & eyr <= 2002 & firm == 1,  a(ind3 eyr) cluster(ind3#eyr)  
coefplot, vertical keep(firmfeI*) yline(0) level(95)
 
**********FIGURE 4(b)**********
reghdfe lny firmfI* nworker if yr >= 1982 & yr <= 2005 & firm == 1, a(yr ind3 eage) cluster(ind3#yr )
coefplot, vertical keep(firmfI*) yline(0) level(95) 
 
 
sum dbanks if tag_geo == 1,d 
bys geo: egen dbanks_geocode = max(dbanks)
gen dbanksH = 0 
replace dbanksH = 1 if dbanks_geocode >  .0764735 
  
**********TABLE 7 Panel A**********
reghdfe lny firmfBefore firmfAfter nworker if yr >= 1992 & yr <= 2005 & firm == 1 & yr != 1997 & yr != 1998 & dbanksH == 1 , a(ind3 yr eage) cluster(ind3#yr)
outreg2 using table1, replace tex

reghdfe lny firmfBefore firmfAfter nworker if yr >= 1992 & yr <= 2005 & firm == 1 & yr != 1997 & yr != 1998 & dbanksH == 0 , a(ind3 yr eage) cluster(ind3#yr)
outreg2 using table1, append tex 

**********TABLE 7 Panel B**********

gen lnmachine = ln(asset_machine) 
gen coll = asset_land + asset_factory
sum coll if yr >= 1992 & yr <= 2005 & firm == 1 & yr != 1997 & yr != 1998,d  
 
reghdfe coll firmfBefore firmfAfter nworker lnmachine if yr >= 1992 & yr <= 2005 & firm == 1 & yr != 1997 & yr != 1998 & dbanksH == 1 & coll < 2408.087 , a(ind3 yr eage) cluster(ind3#yr) 
outreg2 using table1, replace tex

reghdfe coll firmfBefore firmfAfter nworker lnmachine if yr >= 1992 & yr <= 2005 & firm == 1 & yr != 1997 & yr != 1998 & dbanksH == 0 & coll < 2408.087 , a(ind3 yr eage) cluster(ind3#yr) 
outreg2 using table1, append tex 
  
**********Figure 5(a)********** 
gen lnasset_land = ln(asset_land)
reghdfe lnasset_land firmfI* nworker if yr >= 1982 & yr <= 2005 & firm == 1, a(yr ind3 eage) cluster(ind3#yr )
coefplot, vertical keep(firmfI*) yline(0) level(95) 
  
**********Figure 5(b)**********
gen lnasset_factory = ln(asset_factory)
reghdfe lnasset_factory firmfI* nworker if yr >= 1982 & yr <= 2005 & firm == 1, a(yr ind3 eage) cluster(ind3#yr )
coefplot, vertical keep(firmfI*) yline(0) level(95) 

**********Figure 5(c)**********
gen lnasset3 = ln(asset - asset_land - asset_factory)
reghdfe lnasset3 firmfI* nworker if yr >= 1982 & yr <= 2005 & firm == 1, a(yr ind3 eage) cluster(ind3#yr )
coefplot, vertical keep(firmfI*) yline(0) level(95) 
  


**********ALTERNATIVE EXPLANATION**********
 
gen mshare = nworkerm/nworker
gen wage_w = wagesum_white/nworker_white
gen lnwage_w = ln(wage_w)
gen wage_b = wagesum_blue/nworker_blue  
gen lnwage_b = ln(wage_b)
gen ron = revenue/nworker
gen lnron = ln(ron)   
 
**********FIGURE 6(a)**********
reghdfe mshare firmfI* nworker if firm == 1 & yr >=1982 & yr <= 2005, a(yr ind3 eage) cluster(ind3#yr) 
coefplot, vertical keep(firmfI*) yline(0) level(95) 
 
**********FIGURE 6(b)**********
reghdfe lnwage_w firmfI* lnron if firm == 1 & yr >=1982 & yr <= 2005, a(yr ind3 eage) cluster(ind3#yr)
coefplot, vertical keep(firmfI*) yline(0) level(95)

**********FIGURE 6(c)********** 
reghdfe lnwage_b firmfI* lnron if firm == 1 & yr >=1982 & yr <= 2005, a(yr ind3 eage ) cluster(ind3#yr)
coefplot, vertical keep(firmfI*) yline(0) level(95)

  
bys ind2 geo yr: gen Tfirm = _N

gen xx = Tfirm if yr == 1997
bys ind2 geo: egen T1997 = max(xx)
drop xx

gen xx = Tfirm if yr == 1998
bys ind2 geo: egen T1998 = max(xx)
drop xx
 
bys ind2 geo: egen xx = total(firm) if yr == 1998
bys ind2 geo: egen T1998s = max(xx)
drop xx

bys ind2 geo: egen xx = total(firm) if yr == 1997
bys ind2 geo: egen T1997s = max(xx)
drop xx 
 
gen dFails = ln(T1997/T1998)     
gen after_dFails = (yr>=1998)*dFails  

**********TABLE 8**********
reghdfe Fnewg2 after_dFails if tag_ind2_geo_yr == 1 & yr >= 1992 & yr <= 2005, a(yr ind2#geo)  cluster (ind2#geo) 
outreg2 using table1, replace tex 
reghdfe Mnewg2 after_dFails if tag_ind2_geo_yr == 1 & yr >= 1992 & yr <= 2005, a(yr ind2#geo)  cluster (ind2#geo)
outreg2 using table1, append tex
 
**********FIGURE 7**********

gen cost_material_rev = cost_material/revenue 

reghdfe cost_material_rev firmfI* nworker if firm == 1, a(eage yr ind3) cluster(ind3#yr) 
coefplot, vertical keep(firmfI*) yline(0) level(95)
 
  

**********APPENDIX**********  
 
**********FIGURE B1(a)**********
reghdfe Fnewg3 dd* if tag_geo_yr == 1 & yr >= 1992 & yr <= 2005, a(yr geo) cluster(geo)
coefplot, vertical drop(_cons) yline(0) level(95) omitted baselevels

**********FIGURE B1(b)**********
reghdfe Mnewg3 dd* if tag_geo_yr == 1 & yr >= 1992 & yr <= 2005, a(yr geo) cluster(geo) 
coefplot, vertical drop(_cons) yline(0) level(95) omitted baselevels 

**********FIGURE B1(c)**********
reghdfe Fnewg2 dd* if tag_ind2_geo_yr == 1 & yr >= 1992 & yr <= 2005, a(yr ind2#geo) cluster (geo) 
coefplot, vertical drop(_cons) yline(0) level(95) omitted baselevels

**********FIGURE B1(d)**********
reghdfe Mnewg2 dd* if tag_ind2_geo_yr == 1 & yr >= 1992 & yr <= 2005, a(yr ind2#geo) cluster (geo) 
coefplot, vertical keep(dd*) yline(0) level(95) omitted baselevels

**********FIGURE B2**********
gen lnasset = ln(asset)
gen xx = nworker if yr - eyr == 3
bys id: egen nworker_p3 = max(xx)
drop xx  
gen lnnworker_p3 = ln(nworker_p3)  

reghdfe lnnworker_p3 firmfeI* lnasset if tag_id ==1 & eyr >= 1982 & eyr <= 2002 & firm == 1,  a(ind3 eyr) cluster(ind3#eyr)  
coefplot, vertical keep(firmfeI*) yline(0) level(95)

**********TABLE B1 (A)**********
reghdfe Fnewg3 after_dbanks2 if tag_geo_yr == 1 & yr >= 1992 & yr <= 2005, a(yr geo) cluster(geo) 
outreg2 using table1, replace tex
reghdfe Mnewg3 after_dbanks2 if tag_geo_yr == 1 & yr >= 1992 & yr <= 2005, a(yr geo) cluster(geo)
outreg2 using table1, append tex  

**********TABLE B1 (B)**********
reghdfe Fnewg2 after_dbanks2 if tag_ind2_geo_yr == 1 & yr >= 1992 & yr <= 2005, a(yr ind2#geo) cluster (geo)
outreg2 using table1, replace tex
reghdfe Mnewg2 after_dbanks2 if tag_ind2_geo_yr == 1 & yr >= 1992 & yr <= 2005, a(yr ind2#geo) cluster (geo)
outreg2 using table1, append tex

**********TABLE B2 column (1)**********

bys geo yr: egen xx = total(debt) if inc == 1 & asset >= equity
bys geo yr: egen tdebt = max(xx) 
drop xx 
replace tdebt = tdebt/1000 
 

reghdfe Fnewg3 after_dbanks tdebt if tag_geo_yr == 1 & yr >= 1992 & yr <= 2005, a(yr geo) cluster(geo)
outreg2 using table1, replace tex
reghdfe Mnewg3 after_dbanks tdebt if tag_geo_yr == 1 & yr >= 1992 & yr <= 2005, a(yr geo) cluster(geo)
outreg2 using table1, append tex

**********TABLE B2 (column (2))**********
reghdfe Fnewg2 after_dbanks tdebt if tag_ind2_geo_yr == 1 & yr >= 1992 & yr <= 2005, a(yr ind2#geo) cluster (geo)
outreg2 using table1, replace tex
reghdfe Mnewg2 after_dbanks tdebt if tag_ind2_geo_yr == 1 & yr >= 1992 & yr <= 2005, a(yr ind2#geo) cluster (geo)
outreg2 using table1, append tex
 

**********Table B2 column (3)**********
reghdfe Fnewg3 after_treated tdebt if tag_geo_yr == 1 & yr >= 1992 & yr <= 2005 & severe_shock == 1, a(geo yr) cluster(geo)  
outreg2 using table1, replace tex
reghdfe Mnewg3 after_treated tdebt if tag_geo_yr == 1 & yr >= 1992 & yr <= 2005 & severe_shock == 1, a(geo yr) cluster(geo)  
outreg2 using table1, append tex

**********TABLE B3 (falsification test, Service sector)**********

sum Fnew_service if tag_geo_yr == 1 & yr <=1997 
sum Mnew_service if tag_geo_yr == 1 & yr <=1997 
sum Fnew_service if tag_geo_yr == 1 & yr >1997  
sum Mnew_service if tag_geo_yr == 1 & yr >1997  
 
reghdfe Fnew_service after_dbanks if tag_geo_yr == 1 & yr >= 1996 & yr <= 2005, a(yr geo) cluster(geo) 
outreg2 using table1, replace tex
reghdfe Mnew_service after_dbanks if tag_geo_yr == 1 & yr >= 1996 & yr <= 2005, a(yr geo) cluster(geo) 
outreg2 using table1, append tex  

**********TABLE D2 *FEMALE WORKER SHARE AND DEBT**********
gen fshare = nworkerf/nworker 
gen fshareAfter = fshare*after

reghdfe debt fshare fshareAfter lnasset if yr >= 1982 & yr <= 2005 & inc == 1 & asset >= equity, a(yr) cluster(yr)
outreg2 using table1, replace tex
reghdfe debt fshare fshareAfter lnasset if yr >= 1982 & yr <= 2005 & inc == 1 & asset >= equity, a(yr ind3 eage) cluster(ind3#yr ) 
outreg2 using table1, append tex

 




  